<?php
class CentroApoyoEscolaresController extends AppController {

	var $name = 'CentroApoyoEscolares';

	function index() {
		$this->CentroApoyoEscolare->recursive = 0;
		$this->set('centroApoyoEscolares', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid centro apoyo escolare', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('centroApoyoEscolare', $this->CentroApoyoEscolare->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->CentroApoyoEscolare->create();
			if ($this->CentroApoyoEscolare->save($this->data)) {
				$this->Session->setFlash(__('The centro apoyo escolare has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The centro apoyo escolare could not be saved. Please, try again.', true));
			}
		}
		$equiposOperativos = $this->CentroApoyoEscolare->EquiposOperativo->find('list');
		$users = $this->CentroApoyoEscolare->User->find('list');
		$iems = $this->CentroApoyoEscolare->Iem->find('list');
		$this->set(compact('equiposOperativos', 'users', 'iems'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid centro apoyo escolare', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->CentroApoyoEscolare->save($this->data)) {
				$this->Session->setFlash(__('The centro apoyo escolare has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The centro apoyo escolare could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->CentroApoyoEscolare->read(null, $id);
		}
		$equiposOperativos = $this->CentroApoyoEscolare->EquiposOperativo->find('list');
		$users = $this->CentroApoyoEscolare->User->find('list');
		$iems = $this->CentroApoyoEscolare->Iem->find('list');
		$this->set(compact('equiposOperativos', 'users', 'iems'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for centro apoyo escolare', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->CentroApoyoEscolare->delete($id)) {
			$this->Session->setFlash(__('Centro apoyo escolare deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Centro apoyo escolare was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
